package 等待通知_卖包子;

public class ZhengTi <T>{
    private T[] zt;
    private int index=0;
    public ZhengTi(int size){
        zt=(T[]) new Object[size];

    }
    public synchronized void add(T t){
       while (index>=zt.length){
           try {
               this.wait();
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
       }
       zt[index]=t;
       index++;
       notifyAll();
    }
    public synchronized T take(){
        while (index==0){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        index--;
        T t=zt[index];
        notifyAll();
        return t;
    }
}
